﻿import random

random.seed()

walkableTiles = list()

for x in xrange(thisMonster.TilePosition.X-2, thisMonster.TilePosition.X+3):
    for z in xrange(thisMonster.TilePosition.Z-2, thisMonster.TilePosition.Z+3):
        if level.Tiles[x,z] is not None and level.Tiles[x,z].Type == TileTypes.Floor:
            walkableTiles.append((x,z))

if len(walkableTiles) > 1:
    coord = walkableTiles[random.randint(0, len(walkableTiles) - 1  )]
elif len(walkableTiles) == 1:
    coord = walkableTiles[0]
else:
    log.Write("unstick.py couldn't find a walkable tile")
    coord = (thisMonster.TilePosition.X, thisMonster.TilePosition.Z)

thisMonster.TargetTile = Vector3(coord[0], 0, coord[1])

thisMonster.AiState.Pop()
thisMonster.AiState.Push("move")
thisMonster.AiState.Push("pathfinding")